package com.flyco.modules.pms.mapper;

import java.util.List;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.SqlParser;
import com.flyco.modules.oms.entity.OmsOrderItem;
import com.flyco.modules.pms.entity.PmsSkuStock;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.flyco.modules.pms.vo.PmsProductSkuForOrderVO;
import com.flyco.modules.pms.vo.PmsProductSkuVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: SKU
 * @Author: flyco
 * @Date:   2019-11-22
 * @Version: V1.0
 */
@DS("master")
@Repository
public interface PmsSkuStockMapper extends BaseMapper<PmsSkuStock> {

	List<PmsSkuStock> getStockProductCount();

	public boolean deleteByMainId(Long mainId);
    
	public List<PmsSkuStock> selectByMainId(Long mainId);

	public int releaseSkuStockLock(@Param("itemList") List<OmsOrderItem> itemList);

	public int updateSkuStock(@Param("itemList") List<PmsSkuStock> itemList);

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public List<PmsProductSkuVO> getProductSkuList();

	@SqlParser(filter=true)
	public List<PmsProductSkuForOrderVO> getProductSkuForOrderList(@Param("storeId") Long storeId, @Param("skuCodes") List<String> skuCodes);

	public List<PmsProductSkuForOrderVO> queryProductSkuList(@Param("storeIds") List<Long> storeIds, @Param("productSns") List<String> productSns, @Param("skuCodes") List<String> skuCodes);

	/**
	 * 释放锁定的库存
	 */
	public int releaseLockStock(@Param("stockId") Long stockId, @Param("quantity")Integer quantity, @Param("version") Long version);

	/**
	 * 释放锁定的库存
	 */
	public int releaseSkuStockLockByList(@Param("itemList") List<OmsOrderItem> itemList);

}
